<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="text()" name="revert">
    <xsl:param name="text" select="."/>
    <xsl:if test="string-length($text) &gt; 0">
      <xsl:value-of select="substring($text, string-length($text), 1)"/>
      <xsl:call-template name="revert">
        <xsl:with-param name="text" select="substring($text, 1, string-length($text) - 1)"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  
  <!-- copy everything else -->
  <xsl:template match="node()[not(self::text())]|@*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
  
</xsl:stylesheet>
